package test.client43;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class ClientTest01 {
	public static void main( String args[] ) throws Exception {
		new ClientTest01().go();
	}

	private void go() throws Exception {
		CloseableHttpClient cl = HttpClients.createDefault();
		
		HttpGet get = new HttpGet("http://www.yahoo.co.jp/");
		System.out.println(get.toString());
		CloseableHttpResponse r = cl.execute(get);
		try {
			System.out.println(r.getStatusLine().toString());
			HttpEntity e = r.getEntity();
			BufferedReader br = new BufferedReader(new InputStreamReader(e.getContent()));
			String s;
			while( (s=br.readLine()) != null ) System.out.println(s);
			br.close();
			EntityUtils.consume(e);
		} finally {
			r.close();
		}
	}
}
